package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Point;
import com.neusoft.service.PointService;
import com.neusoft.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/PointController")
@RefreshScope //开启动态刷新
public class PointController {
    @Autowired
    private PointService pointService;

    @GetMapping("/checkPoints/{tokenString}")
    public CommonResult checkPoints(@PathVariable("tokenString") String tokenString) throws Exception {
        try {
            TokenUtil.verify(tokenString);
        }catch(Exception e){
            return new CommonResult(401, "Unauthorized", 0);
        }
        if(TokenUtil.verify(tokenString)) {
            String userId = TokenUtil.tokenUser(tokenString);
            List<Point> list = pointService.checkPoints(userId);
            return new CommonResult(200, "success", list);
        }else {
            return new CommonResult(401, "Unauthorized", 0);
        }

    }

}
